

    $(document).ready(function () {
        initPagination();
        querySum();
    });

    //轮播
    $('.pagination-box').on('click', '.pagination-unit', function () {
        $(this).addClass('pagination-unit-active').siblings('.pagination-unit').removeClass('pagination-unit-active')
        var m = $(this).index() / 4 * 100 + '%';
        $('.slider-container').css({
            transform: 'translateX(-' + m + ')'
        })
    })
    //条件查询开始
    $("#distpicker1").distpicker({
        autoSelect: false
    });
    $("#distpicker2").distpicker({
        autoSelect: false
    });



    var inputs = [
        {
            name: '客户姓名',
            className: '.client-name',
            parameter: 'uname_v'
        },
        {
            name: '客户手机号码',
            className: '.client-phone-num',
            parameter: 'uphone_v'
        },
        {
            name: '当前捆绑律师',
            className: '.current-lawyer',
            parameter: 'lawyername_v'
        },
        {
            name: '创建时间start',
            className: '#create-start',
            parameter: 'createTimeStart_v'
        },
        {
            name: '创建时间end',
            className: '#create-end',
            parameter: 'createTimeEnd_v'
        }, {
            name: '首次咨询时间start',
            className: '#first-consult-start',
            parameter: 'firstTimeStart_v'
        }, {
            name: '首次咨询时间end',
            className: '#first-consult-end',
            parameter: 'firstTimeEnd_v'
        }, {
            name: '末次咨询时间start',
            className: '#last-consult-start',
            parameter: 'lastTimeStart_v'
        }, {
            name: '末次咨询时间end',
            className: '#last-consult-end',
            parameter: 'lastTimeEnd_v'
        }, {
            name: '顶级渠道名称',
            className: '.promotion-name',
            parameter: ''
        }, {
            name: '一级渠道名称',
            className: '.first-promotion-name',
            parameter: ''
        }, {
            name: '咨询发起时间start',
            className: '#consult-time-start',
            parameter: ''
        }, {
            name: '咨询发起时间end',
            className: '#consult-time-end',
            parameter: ''
        },
        {
            name: '律师姓名',
            className: '.lawyer-name',
            parameter: 'alawyername_v'
        },
        {
            name: '律师手机号码',
            className: '.lawyer-phone-num',
            parameter: 'lawyerPhone_v'
        }
    ]
    var selects = [
        {
            name: '手机号归属地省',
            className: '#distpicker1 .province',
            parameter: ''
        },
        {
            name: '手机号归属地市',
            className: '#distpicker1 .city',
            parameter: 'uphoneArea_v'
        },
        {
            name: '手机号归属地县',
            className: '#distpicker1 .district',
            parameter: ''
        },
        {
            name: '通话时长',
            className: '.call-time',
            parameter: 'calledDuration_v'
        },
        {
            name: '通话结果',
            className: '.call-result',
            parameter: 'callStatus_v'
        },
        {
            name: '咨询发起方',
            className: '.consult-bearing',
            parameter: 'initiator_v'
        },
        {
            name: '发起位置',
            className: '.consult-place',
            parameter: ''
        },
        {
            name: '律师服务地区省',
            className: '#distpicker2 .province',
            parameter: ''
        },
        {
            name: '律师服务地区市',
            className: '#distpicker2 .city',
            parameter: ''
        },
        {
            name: '律师服务地区县',
            className: '#distpicker2 .district',
            parameter: ''
        },
        {
            name: '律师类型',
            className: '.lawyer-type',
            parameter: ''
        },
        {
            name: '律师隶属组',
            className: '.lawyer-belong-group',
            parameter: ''
        },
        {
            name: '律师状态',
            className: '.lawyer-status',
            parameter: 'lawyerStates_v'
        },
    ]

//  清空
    $('.clear-btn').on('click', function () {
        for (var i = 0; i < inputs.length; i++) {
            var input = inputs[i];
            $(input.className).val('');
        }

        for (var j = 0; j < selects.length; j++) {
            var select = selects[j];
            $(select.className).find('option').eq(0).prop('selected', 'true');
        }
    })
//    查询
    $('.search-btn').on('click', function () {
        //验证手机
        var client_phone = $('.client-phone-num').val() && $('.client-phone-num').val().trim();
        if (client_phone && !(/^1[34578]\d{9}$/.test(client_phone))) {
            alert('请输入正确的电话号');
            return;
        }
        var lawyer_phone = $('.lawyer-phone-num').val() && $('.lawyer-phone-num').val().trim();
        if (lawyer_phone && !(/^1[34578]\d{9}$/.test(lawyer_phone))) {
            alert('请输入正确的电话号');
            return;
        }
        initPagination();
        querySum();
    })


    function getCount() {
        var result=0;
        var json=getJson();
        $.ajax({
            type: "post",
            url: "/data/count",
            data: json,
            async:false,
            dataType: "json",
            success: function (data) {
                  result = data.data;

            }, error: function () {
                alert("报错了");
            }
        });
        return result;
    }
    //分页
    function initPagination() {
        // 创建分页

        var count=getCount();
        $("#Pagination").pagination(count, {
            num_edge_entries: 1, //边缘页数
            num_display_entries: 10, //主体页数
            callback: pageselectCallback, //回调函数
            items_per_page: 10, //每页显示1项
            prev_text: "上一页",
            next_text: "下一页",
            ellipse_text: "...",//省略的文本
            prev_show_always: true,//是否总显示“前一页”分页按钮
            next_show_always: true,//是否总显示“下一页”分页按钮，
        });
    };

    function pageselectCallback(page_index, jq) {

        query(page_index, jq);

    }



    function  getJson(page_index, jq){

        var uname_v=$('.seek-content').find('.client-name').val();
        var uphone_v=$('.seek-content').find('.client-phone-num').val();
        var uphoneArea_v=$('.seek-content').find('#distpicker1 .city').val();
        var lawyername_v=$('.seek-content').find('.current-lawyer').val();
        var alawyername_v=$('.seek-content').find('.lawyer-name').val();
        var alawyerphone_v=$('.seek-content').find('.lawyer-phone-num').val();

        var aprovince_index=$('#distpicker2').find('.province')["0"].selectedIndex;
        var aprovince_v=$('#distpicker2').find('.province')["0"][aprovince_index].attributes[1].nodeValue;

        var acity_index=$('#distpicker2').find('.city')["0"].selectedIndex;
        var acity_v=$('#distpicker2').find('.city')["0"][acity_index].attributes[1].nodeValue;

        var adistrict_index=$('#distpicker2').find('.district')["0"].selectedIndex;
        var adistrict_v=$('#distpicker2').find('.district')["0"][adistrict_index].attributes[1].nodeValue;

        var firstTimeStart_v=$('.seek-content').find('#first-consult-start').val();
        var firstTimeEnd_v=$('.seek-content').find('#first-consult-end').val();
        var lastTimeStart_v=$('.seek-content').find('#last-consult-start').val();
        var lastTimeEnd_v=$('.seek-content').find('#last-consult-end').val();
        var createTimeStart_v=$('.seek-content').find('#create-start').val();
        var createTimeEnd_v=$('.seek-content').find('#create-end').val();
        var lawyerPhone_v=$('.seek-content').find('.lawyer-phone-num').val();
        var lawyerStates_v=$('.seek-content').find('.lawyer-status').val();
        var initiator_v=$('.seek-content').find('.consult-bearing').val();
        var callStatus_v=$('.seek-content').find('.call-result').val();
        //发起位置
        var consult_place_v=$('.seek-content').find('.consult-place').val();



        var startTimeStart_v=$('.seek-content').find('#consult-time-start').val();
        var startTimeEnd_v=$('.seek-content').find('#consult-time-end').val();
        var calleffect_v=$('.seek-content').find('.call-time').val();

        var callStatus_vv="" ;
        var rejectStatus_v="";
        if(callStatus_v){
              callStatus_vv=callStatus_v.split("#")[0];
              rejectStatus_v=callStatus_v.split("#")[1];
        }

        if(typeof(page_index)=="undefined"){
            page_index=0;
            firsttime=true;
        }
        var acid_v='';
        if(aprovince_v){
            acid_v=aprovince_v;
        }
        if(acity_v){
            acid_v=acity_v;
        }
        if(adistrict_v){
            acid_v=adistrict_v;
        }

        var json = {
            uname: uname_v,
            uphone: uphone_v,
            uphoneArea: uphoneArea_v,
            lawyername: lawyername_v,
            alawyername: alawyername_v,
            firstTimeStart: firstTimeStart_v,
            firstTimeEnd: firstTimeEnd_v,
            lastTimeStart: lastTimeStart_v,
            lastTimeEnd: lastTimeEnd_v,
            createTimeStart: createTimeStart_v,
            createTimeEnd: createTimeEnd_v,
            lawyerPhone: lawyerPhone_v,
            lawyerStates: lawyerStates_v,
            initiator: initiator_v,
            callStatus: callStatus_vv,
            rejectStatus:rejectStatus_v,
            startTimeStart: startTimeStart_v,
            startTimeEnd: startTimeEnd_v,
            calleffect:calleffect_v,
            proid:consult_place_v,
            acid:acid_v,
             pageNum:page_index+1
        };
        return json;
    }


    function query(page_index, jq) {

        var json=getJson(page_index, jq);
        $.ajax({
            type: "post",
            url: "/data/querydataAnalyseList",
            data: json,
            async:false,
            dataType: "json",
            success: function (data) {
                var result = data.data;
                var tmpl1 = bt('list1', result);
                document.getElementById('tbody1').innerHTML = tmpl1;
                var tmpl3 = bt('list3', result);
                document.getElementById('tbody3').innerHTML = tmpl3;
                var tmpl4 = bt('list4', result);
                document.getElementById('tbody4').innerHTML = tmpl4;
            }, error: function () {
                alert("报错了");
            }
        });

    }

    function querySum() {
        var json=getJson();
        $.ajax({
            type: "post",
            url: "/data/sum",
            data: json,
            async:false,
            dataType: "json",
            success: function (data) {
                var result = data.data;
                var tmpl1 = bt('list0', result);
                document.getElementById('tbody0').innerHTML = tmpl1;
            }, error: function () {
                alert("报错了");
            }
        });

    }
    function exportxls() {
        var json = getJson();
        location.href="/data/exportExcel?uname="+json.uname+"&uphone="+json.uphone+"&uphoneArea="+json.uphoneArea
            +"&lawyername="+json.lawyername+"&alawyername="+json.alawyername+"&firstTimeStart="+json.firstTimeStart+"&lastTimeStart="+json.lastTimeStart
            +"&lastTimeEnd="+json.lastTimeEnd+"&createTimeStart="+json.createTimeStart+"&createTimeEnd="+json.createTimeEnd+"&lawyerPhone="+json.lawyerPhone
            +"&lawyerStates="+json.lawyerStates+"&initiator="+json.initiator+"&callStatus="+json.callStatus+"&startTimeStart="+json.startTimeStart
            +"&startTimeEnd="+json.startTimeEnd+"&calleffect="+json.calleffect+"&acid="+json.acid;
    }

